/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.dao;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.thinkgem.jeesite.common.persistence.BaseDao;
import com.thinkgem.jeesite.common.persistence.BaseDaoImpl;
import com.boxin.ims.modules.wechat.entity.WechatScene;

/**
 * 微信带参数的二维码DAO接口
 * @author xiaoqian
 * @version 2014-03-18
 */
public interface WechatSceneDao extends WechatSceneDaoCustom, CrudRepository<WechatScene, Long> {

	@Modifying
	@Query("delete from  WechatScene   where id = ?1")
	public int deleteById(Long id);
	
	@Query("from  WechatScene   where user.id = ?1 and scene_id=?2 ")
	public WechatScene wechatSceneBySceneId(Long user_id,Long sceneId );
	
	@Query(" select max(sceneId)  from  WechatScene   where user.id = ?1 and qrcode_type='QR_LIMIT_SCENE'" )
	public Long getSceneId(Long user_id);
	
	@Query(" select max(sceneId)  from  WechatScene   where user.id = ?1 and qrcode_type='QR_SCENE'" )
	public Long getSceneIdStr(Long user_id);
	
	@Query("from  WechatScene   where user.id = ?1 and scene_id=?2 ")
	public WechatScene wechatSceneBySceneId(Long user_id,String sceneId );
	
	@Query("from  WechatScene   where user.id = ?1 and scene_id=?2 and ticket =?3")
	public WechatScene wechatSceneByTicket(Long user_id,String sceneId , String ticket );
	
}

/**
 * DAO自定义接口
 * @author xiaoqian
 */
interface WechatSceneDaoCustom extends BaseDao<WechatScene> {

}

/**
 * DAO自定义接口实现
 * @author xiaoqian
 */
@Component
class WechatSceneDaoImpl extends BaseDaoImpl<WechatScene> implements WechatSceneDaoCustom {

}
